home *** CD-ROM | disk | FTP | other *** search
- ;DELBUT revised to take a Path
- ; DELBUT nonexistant-name will delete NO files. With some safety features
- ; (say, /! on command line), it could work in .BAT files without the 'Y/N'
- ; that makes DEL *.* useless.
- ; It can delete itself...
-
- PAGE ,132
- S00000 SEGMENT BYTE PUBLIC 'code'
- ASSUME CS:S00000
- ASSUME SS:S00000
- ASSUME DS:S00000
- ASSUME ES:S00000
-
- cr equ 0Dh
- lf equ 0Ah
- tab equ 9
-
- H00000 DB 256 DUP(?)
- P00100 PROC NEAR
-
- JMP Begin
-
- Instrux DB cr,lf,'DELBUT v 2.0 '
- DB 'by Scott Pakin 2/85, rewritten by J.E. Arkay 5/88',cr,lf
- DB cr,lf,cr,lf
- DB 'Deletes all files in one directory EXCEPT '
- DB 'those matching one filespec.',cr,lf,cr,lf
- DB 'Syntax: [d:][\path\]DELBUT [d:][\path\]filespec'
- DB cr,lf,cr,lf
- DB 'Will not delete Hidden or Read-Only files.',cr,lf
- DB 'Requires DOS 2.0 up. Put it in your DOS directory.'
- DB cr,lf,cr,lf
- DB 'Example for your RAM disk:'
- DB cr,lf,'To delete all except AutoCAD .OVL files,'
- DB cr,lf,cr,lf
- DB tab,' DELBUT D:ACAD*.*'
- CrLf DB cr,lf,'$',1Ah
-
- ParamMsg DB cr,lf,'DELBUT -- Invalid filespec',cr,lf,'$'
- NoFiles DB cr,lf,'DELBUT -- No files found',cr,lf,'$'
- NotFound DB cr,lf
- DB 'DELBUT -- Filespec not found; no files deleted',cr,lf
- DB '( use DEL to delete all files )',cr,lf,'$'
- InvalidDrv DB cr,lf,'DELBUT -- Invalid drive',cr,lf,'$'
- AllMatch DB cr,lf,'DELBUT -- All files match spec, none deleted',cr,lf,'$'
- Deleting DB 'Deleting $'
- ParseMsg DB cr,lf,'DELBUT -- Error parsing filename',cr,lf,'$'
-
- FoundFCB DB 44 DUP(?)
- DTAtoStay DB 44 DUP(0)
- DTAtoDelete DB 44 DUP(?)
- CmdLineBuffer DB 128 DUP(0)
- WildFilespec DB 128 DUP(0)
- StarDotStar DB '*.*',0
- DeleteFlag DB 0
- LastCharOffset DW 0
- NameOffset DW 0
-
- Begin:
- CLD
- MOV DX,offset DTAtoStay
- MOV AH,1AH ;set DTA for DOS funcs 4Eh & 4Fh
- INT 21H
-
- MOV SI,80H
- MOV CL,[SI] ;get Parameter length
- OR CL,CL ;is it zero ?
- JNZ ChkParams
- ;display the instructions
- MOV DX,offset Instrux
- JMP SHORT ShoMsg
-
- ChkParams:
- ;find valid characters in parameter area of PSP, and mov 'em to CmdLineBuffer
- ;Allowed are std filename chars, and \ ? * : and / for those who use it.
- MOV DI,offset CmdLineBuffer
- INC SI ;to 1st char of params
- XOR CH,CH ;now CX is length of params
- CharLoop:
- MOV AL,[SI] ;get a character
- CMP AL,cr ;is this one past the last char ?
- JZ FindFirst
- CMP AL,'!'
- JZ Movit
- CMP AL,' ' ;space
- JZ Skipit
- Cmp AL,tab
- JZ Skipit
- CMP AL,23h
- JL ParamsNFG
- CMP AL,2Ah ; * allowed
- JLE Movit
- CMP AL,'-'
- JZ Movit
- CMP AL,2Eh ; . and / allowed
- JL ParamsNFG
- CMP AL,':'
- JLE Movit
- CMP AL,'?'
- JL ParamsNFG
- CMP AL,'Z'
- JLE Movit
- CMP AL,'\'
- JZ Movit
- CMP AL,5Eh
- JL ParamsNFG
- CMP AL,7Ch
- JZ ParamsNFG
- Movit: MOVSB
- NextChar:
- LOOP CharLoop
- JMP SHORT FindFirst
-
- Skipit:
- INC SI
- JMP SHORT NextChar
- ;-------------------------------------
- FindFirst:
- MOV DX,offset CmdLineBuffer ;holding Cmd Line as entered
- DEC DI ;to last char moved
- SUB DI,DX ;offset in DTA of last char
- MOV LastCharOffset,DI
- XOR CX,CX ;normal files only
- MOV AH,4Eh ;Find first matching file, to DTAtoStay
- INT 21H
- ;Now DTAtoStay begins with the parsed command line drive & filename. If you
- ;entered DELBUT d:\test\*.12, it starts 04,'????????12 ',0.
- ;The found FNAME.EXT,0 is at 1Eh=30d in the DTA (no spaces, variable length)
- JNC ChkIfAnyFiles
-
- ;likely errors
- MOV DX,offset NotFound ;There are no files NOT to delete
- ShoMsg: MOV AH,9
- INT 21H
- MOV AX,4C01h ;exit w/Errorlevel = 1
- INT 21h
-
- ParamsNFG:
- MOV DX,offset ParamMsg
- JMP SHORT ShoMsg
-
- ChkIfAnyFiles:
- ;copy CmdLineBuffer to get the path for WildFilespec
- MOV SI,offset CmdLineBuffer
- MOV DI,offset WildFilespec
- MOV CX,128 ;decimal
- REP MOVSB
-
- ;Look backwards for the start of the filename.ext
- ;The char preceding the name will be a / or \ or : or we're at CmdLineBuffer
- MOV SI,offset WildFilespec
- ADD SI,LastCharOffset ;point to last char of filespec
- STD ;go backwards
- LookLoop:
- LODSB ;DS:[SI] -> AL and DEC SI
- CMP SI,offset WildFilespec
- JL ReplaceName
- INC SI ;'cause SI is 1 BELOW the '\'
- CMP AL,'\'
- JZ ReplaceName
- CMP AL,'/'
- JZ ReplaceName
- CMP AL,':'
- JZ ReplaceName
- DEC SI
- JMP SHORT LookLoop
-
- ;make the name *.*
- ReplaceName: ;SI points 1 before start of name.ext
- CLD ;go forwards
- INC SI ;to start of name in WildFilespec
- MOV DI,SI
- MOV DX,offset WildFilespec
- SUB SI,DX
- MOV NameOffset,SI
- MOV SI,offset StarDotStar
- MOV CX,4
- REP MOVSB
-
- MOV DX,offset DTAtoDelete
- MOV AH,1Ah ;change DTA (was DTAtoStay)
- INT 21h
-
- MOV DX,offset WildFilespec
- XOR CX,CX ;normal files only
- MOV AH,4Eh ;find first match
- INT 21h
- JNC EachFile
- MOV DX,offset NoFiles
- JMP ShoMsg
-
- ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- ;Now delete any files in the directory that don't match the Filespec
- ; Start with Find First Match already called, found match in DTAtoDelete
-
- ; Compare the found filename in DTAtoDelete with the parsed name in DTAtoStay
- ; Works like DOS (which is not, of course, the way you wish it would):
- ; DELBUT ?????.?? matches ABCDE.12 and ABCD.12 and ABC.1 but not ABCD.123
-
- EachFile: ;this is approx 0601 in the code
- MOV SI,offset DTAtoDelete+30 ;NAME.EXT,0 (variable length)
- MOV DI,offset FoundFCB
- XOR AL,AL ;no special features
- MOV AH,29h ;parse filename, no paths
- INT 21h
- CMP AL,0FFh
- JNZ ParseOK
- MOV DX,offset ParseMsg
- JMP ShoMsg
- ParseOK:
- MOV SI,offset DTAtoStay+1 ;11-char parsed filename from cmd line
- MOV DI,offset FoundFCB+1 ;parsed found filename
- MOV CX,11
- MaskLoop:
- LODSB ;[SI] to AL & INC SI
- CMP AL,'?'
- JNZ NextOne
- ;a '?' has been found, copy it to the corresponding location
- MOV [DI],AL
- NextOne:
- INC DI
- LOOP MaskLoop
-
- ;now compare the parsed name in FoundFCB
- Compare:
- MOV DI,offset DTAtoStay+1 ;11-char parsed filename from cmd line
- MOV SI,offset FoundFCB+1
- Mov CX,11
- REPZ CMPSB
- JZ ChkNLoop ;spec matches, don't delete it
-
- ;File does not match the command line filespec
-
- ;copy the name.ext after the path for Delete (func 41h)
- MOV DI,offset CmdLineBuffer
- ADD DI,NameOffset
- MOV SI,offset DTAtoDelete+30 ;decimal, locn of ASCIIZ fname.ext
- FnameLoop:
- MOV AL,[SI]
- MOVSB
- OR AL,AL
- JZ ShoName
- JMP SHORT FnameLoop
-
- ShoName:
- MOV DX,offset Deleting
- MOV AH,9
- INT 21H
- MOV SI,offset DTAtoDelete+30 ;decimal, locn of ASCIIZ fname.ext
- CALL DisplASCIIZ
- MOV DX,offset CmdLineBuffer ;now name.ext is replaced
- MOV AH,41h ;Delete File per ASCIIZ string
- INT 21H
- MOV DeleteFlag,1 ;signal that something was deleted
- ChkNLoop:
- MOV AH,4Fh ;Find Next (any), name to DTAtoDelete
- INT 21H
- JNC EachFile ;process this file if no errors
-
- CMP DeleteFlag,1 ;was anything deleted ?
- JZ Exit ;yes, no message
- MOV DX,offset AllMatch
- JMP ShoMsg ;and exit w/Errorlevel=1
- Exit:
- MOV AX,4C00h ;exit w/Errorlevel=0
- INT 21H
- ;---------------------------------------------------------
- ;Display the ASCIIZ string pointed to by SI and do a CR,LF
- DisplASCIIZ:
- LODSB
- OR AL,AL
- JZ DisplayDone
- MOV DL,AL
- MOV AH,2 ;Display Output 1 char
- INT 21H
- JMP DisplASCIIZ
- DisplayDone:
- MOV DX,offset CrLf
- MOV AH,9
- INT 21H
- RET
-
- P00100 ENDP
- S00000 ENDS
- END P00100